<?php

/**
 * This class implements a stack for pushing existing files.
 * Data pushed is a file path. If the file doens't exist 
 * an error is triggered and the path is not added to the stack  
 * 
 * @author Pablo
 * @since 1.0
 */

// Class dependencies
require_once __DIR__.DS.'blgStack.php';

class blgFilesStack extends blgStack {
	
	public function push($data, $unique= FALSE) {
		if(is_file($data)){		
			array_push($this->stack, $data);
			if($unique)
				$this->stack= array_unique($this->stack);
		}
		else{
			$caller= caller_info();
			trigger_error("FILE STACK ERROR: files '".$data."' does not exist on file system at line ".$caller->line." in ".$caller->file, E_USER_ERROR);
		}
	}
	
	public function require_files(){
		foreach($this->stack as $filePath){
			require($filePath);
		}
	}
	
	public function require_once_files(){
		foreach($this->stack as $filePath){
			require_once($filePath);
		}
	}
	
	public function implode_files($char="\n\n"){
		$return = '';
		ob_start();
		foreach($this->stack as $filePath){			
			require($filePath);		
			echo $char;		
		}	
		$return .= ob_get_contents();
		ob_end_clean();
		return trim($return);					
	}
	

}